#include "iplayer.h"

int skin_porc(void* object, int message, int wparam, void* lparam);

// override interface
int         main_onactivated      	(void* self, SDL_Event* e);
int         main_oninitwindow		(void* self);
int         main_onpaint          	(void* self);

int main(int argc, char* argv[])
{
	PSKIN_WINDOW pwnd = 0;
	int done = 0;

	if (SDL_Init(SDL_INIT_VIDEO) < 0)
	{
		printf("Couldn't init SDL");
		exit(1);
	}

#if (SDL_TTF_USE == 1)
	// Initialize TTF
	if (TTF_Init() == -1)
	{
		printf("Couldn't init SDL_TTF");
		exit(1);
	}
#endif
	atexit(SDL_Quit);
	pwnd = skin_createwindow(SDL_HWSURFACE | SDL_RESIZABLE, 32, 640, 360, 0); // skin_porc);
	if (pwnd)
	{
		int ret = 0;

		// override
		SKIN_OVERRIDE(pwnd, OnActivated, 	main_onactivated);
		SKIN_OVERRIDE(pwnd, OnInitWindow, 	main_oninitwindow);
		SKIN_OVERRIDE(pwnd, OnPaint,		main_onpaint);
    
    	// waiting for window close event..
    	skin_wait_close(pwnd);
	}

#if (SDL_TTF_USE == 1)
	TTF_Quit();
#endif

	SDL_Quit();
	return 0;
}

// override functions
int         main_onactivated      (void* self, SDL_Event* e)
{
    PSKIN_WINDOW p = (PSKIN_WINDOW) self;
    printf("Main.OnActivated(type(%d), gain(%d), state(%d))\r\n", 	e->active.type,
                                                             		e->active.gain,
                                                             		e->active.state);
    return skin_onactivated(self, e);
}

int         main_oninitwindow		(void* self)
{
    PSKIN_WINDOW p = (PSKIN_WINDOW) self;
    PSKIN_CLIENT control = 0;
    printf("Main.OnInitWindow()\r\n");

    // create font
    skin_create_font(p, "/Library/Fonts/NanumGothic.ttc", 14);

    // create control
    control = skin_create_control(p, CONTROL_STATIC, 100, 100, 100, 20, 100, "Static Control");
    control = skin_create_control(p, CONTROL_BUTTON, 250, 100, 100, 20, 101, "Button");
    return skin_oninitwindow(self);
}

int         main_onpaint          (void* self)
{
    SDL_Rect rect;
    PSKIN_WINDOW p = (PSKIN_WINDOW) self;
    printf("Main.OnPaint()\r\n");
    rect.x = rect.y = 0;
    rect.w = 640;
    rect.y = 360;
    SDL_FillRect(p->screen, &rect, SDL_MapRGB(p->screen->format, 0, 0, 0));
    // draw controls..
    skin_draw_controls(p);
    SDL_Flip(p->screen);
    return skin_onpaint(self);
}